<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
        <title>首页</title>
        <!-- 引入 FrozenUI -->
        <link rel="stylesheet" href="http://i.gtimg.cn/vipstyle/frozenui/2.0.0/css/frozen.css"/>
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    </head>
    <body>
        <header class="ui-header ui-header-positive ui-border-b">
            <h1>首页</h1>
            {{if .isLogin}}
            <button class="ui-btn" type="button" onclick="logout(this)">退出</button>
            {{end}}
        </header>
        <section class="ui-container">            
            <div class="ui-form ui-border-t">
                <ul class="ui-list ui-border-tb">
                    {{ range .topicList }}
                    <li>
                        <a href="/topic/tdetails/{{.ID}}">
                            <div class=" ui-list-img-vertical">                    
                                <span style="background-image:url({{.Mimg}})"></span>
                            </div>
                        </a>
                        <div class="ui-list-info ui-border-t">
                            <a href="/topic/tdetails/{{.ID}}">
                                <h4 class="ui-nowrap">{{.Title}}</h4>
                            <p class="ui-nowrap">{{.Content}}</p>
                            </a>
                        </div>
                    </li>
                    {{ end }}
                </ul>
            </div>
        </section>
        
        <footer class="ui-footer ui-footer-btn">
            <ul class="ui-tiled ui-border-t">
                <li data-href="ui.html" class="ui-border-r" onclick="disk(1)"><div>分类</div></li>
                {{if .isLogin}}
                <li data-href="index.html" class="ui-border-r" onclick="getlogin('/topic/add')"><div>发布信息</div></li>
                {{else}}
                <li data-href="js.html" onclick="getlogin('/login')"><div>登录/注册</div></li>
                {{end}}
            </ul>
        </footer>
        <div class="ui-dialog ui-dialog-operate ui-dialog-operate-icon show" id="layk" style="display: none;">
            <div class="ui-dialog-cnt">
                
                <div class="ui-dialog-bd">
                    <h3>选择分类</h3>
                    {{range .typeList}}
                    <a class="ui-btn-lg ui-btn-primary"  href="/topic/tlist?tid={{.ID}}" style="margin:10px 0px;">{{.Name}}</a>
                    {{end}}
                </div>
                  <i class="ui-dialog-close" data-role="button" onclick="disk(0)"></i>
            </div>
        </div>
<script>
    function getlogin(tourl){
        location.href = tourl;
    }
    function disk(nstatus){
        var layk = document.getElementById("layk");
        if (nstatus == 0){
            layk.style.display = "none";
        }else if(nstatus == 1){
            layk.style.display = "";
        }
    }
    function logout(oDom){
        axios({
            method: 'post',
            url: '/logout',
        }).then(function(response) {
            if (response.data.status == 1){
                oDom.remove();
                location.reload();
            };
        });
    }
</script>
    </body>
</html>